package com.zzy.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzy.mapper.UserMapper;
import com.zzy.domain.dto.PageResultDto;
import com.zzy.domain.User;
import com.zzy.domain.vo.PageQuery;
import com.zzy.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserService{
    private final UserMapper userMapper;

    @Override
    public PageResultDto<User> page(PageQuery pageQuery) {
        PageHelper.startPage(pageQuery.getPage(),pageQuery.getPageSize());
        List<User>list=userMapper.list(pageQuery);
        Page<User>list1= (Page<User>) list;
        return new PageResultDto(list1.getTotal(),list1);
    }

    @Override
    public Integer add(User user) {
        return userMapper.add(user);
    }

    @Override
    public User show(Integer id) {
        // 修正方法名，与mapper保持一致
        return  userMapper.getById(id);
    }

    // 修正修改方法实现
    @Override
    public Integer update(User user) {
        return userMapper.update(user);
    }



    //新增删除方法实现
    @Override
    public Integer delete(Integer id) {
        return userMapper.delete(id);
    }
}